package com.UI
{
	import com.*;
	import com.Engine.*;
	import com.Packet.*;
	
	import flash.display.*;
	import flash.events.*;
	import flash.external.*;
	import flash.filters.*;
	import flash.geom.*;
	import flash.system.*;
	import flash.text.*;
	import flash.ui.*;
	import flash.utils.*;
	
	import org.aswing.*;
	import org.aswing.border.*;
	import org.aswing.border.EmptyBorder;
	import org.aswing.colorchooser.*;
	import org.aswing.ext.*;
	import org.aswing.geom.*;
	/**
	 * ToolTipItem
	 */
public	class PanelToolTipItem extends JPanel{
		
	//members define
	protected var panelTop:JPanel;
	protected var panelIcon:JPanel;
	protected var labelName:JLabel;
	protected var labelLevel:JLabel;
	protected var panelBottom:JPanel;
	protected var textField:MultilineLabel;
	
		
	/**
	 * ToolTipItem Constructor
	 */
	public function PanelToolTipItem(){
		//component creation
		setLocation(new IntPoint(0, 0));
		setSize(new IntDimension(200, 69));
		var layout0:BorderLayout = new BorderLayout();
		layout0.setHgap(0);
		layout0.setVgap(0);
		setLayout(layout0);
		
		panelTop = new JPanel();
		panelTop.setLocation(new IntPoint(5, 5));
		panelTop.setSize(new IntDimension(250, 65));
		panelTop.setPreferredSize(new IntDimension(200, 65));
		panelTop.setConstraints("North");
		var layout1:EmptyLayout = new EmptyLayout();
		panelTop.setLayout(layout1);
		
		panelIcon = new JPanel();
		panelIcon.setLocation(new IntPoint(10, 10));
		panelIcon.setSize(new IntDimension(45, 45));
		panelIcon.setPreferredSize(new IntDimension(45, 45));
		
		labelName = new JLabel();
		labelName.setLocation(new IntPoint(55, 15));
		labelName.setSize(new IntDimension(135, 20));
		labelName.setPreferredSize(new IntDimension(135, 20));
		labelName.setText("label");
		
		labelLevel = new JLabel();
		labelLevel.setLocation(new IntPoint(55, 35));
		labelLevel.setSize(new IntDimension(135, 20));
		labelLevel.setPreferredSize(new IntDimension(135, 20));
		labelLevel.setText("label");
		
		panelBottom = new JPanel();
		panelBottom.setLocation(new IntPoint(0, 50));
		panelBottom.setSize(new IntDimension(200, 26));
		var layout2:CenterLayout = new CenterLayout();
		panelBottom.setLayout(layout2);
		
		textField = new MultilineLabel();
		textField.setLocation(new IntPoint(50, 11));
		textField.setSize(new IntDimension(100, 4));
		
		//component layoution
		append(panelTop);
		append(panelBottom);
		
		panelTop.append(panelIcon);
		panelTop.append(labelName);
		panelTop.append(labelLevel);
		
		panelBottom.append(textField);
		
		//-------------------------------------------------------
		var filter:GlowFilter;
		var font:ASFont = new ASFont("宋体", 14, false, false, false, false);
		filter = new GlowFilter(0x000000, 1, 2, 2, 10);
		labelName.setFont(font);
		labelName.setForeground(ASColor.WHITE);
		labelName.setTextFilters(new Array(filter));
		
		labelLevel.setFont(font);
		labelLevel.setForeground(ASColor.ORANGE);
		labelLevel.setTextFilters(new Array(filter));
		
		textField.setBackgroundDecorator(null);
		textField.setWordWrap(true);
		textField.setFont(new ASFont("宋体", 13, false, false, false, false));
		textField.setForeground(ASColor.WHITE);
		textField.setPreferredWidth(180);
		//var filter:GlowFilter;
		//filter = new GlowFilter(0x000000, 1, 2, 2, 10);
		textField.filters = (new Array(filter));
		//setItem(item);
		//this.setBackground(new ASColor(0x033300,1.0));
		
		//setBorder(new LineBorder(null,new ASColor(0xeeeeee,1.0)));
		//textField.setBounds(new IntRectangle(5,5,5,5));
		labelLevel.setText("");
	}
	public var isEquiped:Boolean = false;
	private var icon_id:int = 0;
	private var filterArrayImage:Array = new Array(new GlowFilter(0xEA0000, 0.6, 34, 34, 2,1,true));
	public function setItem(item:Object):void 
	{
		//setTipText("");
		if(item == null)
		{
			icon_id = 0;
			panelIcon.setBackgroundDecorator(null);
			return;
		}
		
		var objItemCSV:Object = Client.getInstance().GetItemCSV(item.csv_id);
		if(objItemCSV == null)
		{
			icon_id = 0;
			panelIcon.setBackgroundDecorator(null);
			return;
		}
		if(icon_id != objItemCSV.icon_id)
		{
			icon_id = objItemCSV.icon_id;
			var dis:DisplayObject = Client.getItemElement("img_item_"+objItemCSV.icon_id) as DisplayObject;
			panelIcon.setBackgroundDecorator(dis != null ? new AssetBackground(dis) : null);
		}
		labelLevel.setText("");
		if(objItemCSV.type == Const.ITEM_TYPE_EQUIP)
		{
			labelName.setText((isEquiped?'(身上)':'')+objItemCSV.name);
			labelLevel.setText('Lv.' + item.equip_level);
		}
		else
			labelName.setText(objItemCSV.name);
		
		
		var text:String = new String;
		//text += objItemCSV.name+"\n"
		if(objItemCSV.description.length != 0)
			text += objItemCSV.description +"\n";
		text += "\n"
		text += "类型:   "
		if(objItemCSV.type == Const.ITEM_TYPE_PROPS) text += "道具\n";//道具
		if(objItemCSV.type == Const.ITEM_TYPE_EQUIP) text += "装备\n";//装备
		if(objItemCSV.type == Const.ITEM_TYPE_ATLAS) text += "图谱\n";//图谱
		if(objItemCSV.type == Const.ITEM_TYPE_GEM) text += "宝石\n";//宝石
		if(objItemCSV.type == Const.ITEM_TYPE_MATERIAL) text += "材料\n";//材料
		if(objItemCSV.type == Const.ITEM_TYPE_PET_EGG) text += "宠物蛋n";//宠物蛋
		if(objItemCSV.type == Const.ITEM_TYPE_PET_BOOK) text += "宠物技能书\n";//宠物技能书
		
		if(objItemCSV.type == Const.ITEM_TYPE_EQUIP)
		{
			text += '<font color="#FFFF00">装备等级:   '+item.equip_level+"</font>\n";
			text += "装备类型:   "
			if(objItemCSV.equip_type == 0) text += "帽子\n";//装备
			if(objItemCSV.equip_type == 1) text += "衣服\n";//装备
			if(objItemCSV.equip_type == 2) text += "腰带\n";//装备
			if(objItemCSV.equip_type == 3) text += "武器\n";//装备
			if(objItemCSV.equip_type == 4) text += "裤子\n";//装备
			if(objItemCSV.equip_type == 5) text += "鞋子\n";//装备
		}
		
		var enableUse:Boolean = true;
		if(objItemCSV.require_level > 0)
		{
			if(CharInfo.m_nLevel < objItemCSV.require_level)
			{
				text += '<font color="#FF0000">等级要求:   '+objItemCSV.require_level +"</font>\n"
				enableUse = false;
			}
			else
				text += "等级要求:   "+objItemCSV.require_level +"\n"
		}	
		
		if(objItemCSV.require_race >= 0)
		{
			if(CharInfo.m_nRace != objItemCSV.require_race)
			{
				text += '<font color="#FF0000">种族要求:   '+(objItemCSV.require_race==0?"人":(objItemCSV.require_race==1?"魔":"仙")) +"</font>\n"
				enableUse = false;
			}
			else
				text += "种族要求:   "+(objItemCSV.require_race==0?"人":(objItemCSV.require_race==1?"魔":"仙")) +"\n"
		}
		
		if(objItemCSV.require_gender >= 0)
		{
			if(CharInfo.m_nGender != objItemCSV.require_gender)
			{
				text += '<font color="#FF0000">性别要求:   '+(objItemCSV.require_gender == 0?"男":"女") +"</font>\n"
				enableUse = false;
			}
			else
				text += "性别要求:   "+(objItemCSV.require_gender == 0?"男":"女") +"\n";
		}
		
		text += "\n";
		if(objItemCSV.type == Const.ITEM_TYPE_EQUIP)//装备
		{
			//if(item.equip_hp_max > 0 || item.equip_ep_max > 0|| item.equip_ap > 0|| item.equip_sp > 0
			//	|| item.equip_resistHY > 0|| item.equip_resistZS > 0|| item.equip_resistJD > 0)
			//	text += "\n装备属性:\n";
			if(item.equip_hp > 0)
				text += "生命   "+'<font color="#FFFF00">+'+item.equip_hp+"</font>\n";
			
			if(item.equip_ap > 0)
				text += "攻击   "+'<font color="#FFFF00">+'+item.equip_ap+"</font>\n";
			
			if(item.equip_dp > 0)
				text += "防御   "+'<font color="#FFFF00">+'+item.equip_dp+"</font>\n";
			
			if(item.equip_sp > 0)
				text += "速度   "+'<font color="#FFFF00">+'+item.equip_sp+"</font>\n";
			
			
			if(item.equip_enhanceHL > 0)
				text += "强混乱   "+'<font color="#FF0000">+'+item.equip_enhanceHL+"</font>\n";
			if(item.equip_enhanceBD > 0)
				text += "强冰冻   "+'<font color="#FF0000">+'+item.equip_enhanceBD+"</font>\n";
			if(item.equip_enhanceHS > 0)
				text += "强昏睡   "+'<font color="#FF0000">+'+item.equip_enhanceHS+"</font>\n";
			
			if(item.equip_resistHL > 0)
				text += "抗混乱   "+'<font color="#FFFF00">+'+item.equip_resistHL+"</font>\n";
			
			if(item.equip_resistBD > 0)
				text += "抗冰冻   "+'<font color="#FFFF00">+'+item.equip_resistBD+"</font>\n";
			
			if(item.equip_resistHS > 0)
				text += "抗昏睡   "+'<font color="#FFFF00">+'+item.equip_resistHS+"</font>\n";
			
			if(item.equip_prop_BJ > 0)
				text += "暴击率   "+'<font color="#FFFF00">+'+item.equip_prop_BJ+"</font>\n";
			if(item.equip_prop_SB > 0)
				text += "闪避率   "+'<font color="#FFFF00">+'+item.equip_prop_SB+"</font>\n";
			if(item.equip_prop_FJ > 0)
				text += "反击率   "+'<font color="#FFFF00">+'+item.equip_prop_FJ+"</font>\n";
			if(item.equip_prop_LJ > 0)
				text += "连击率   "+'<font color="#FFFF00">+'+item.equip_prop_LJ+"</font>\n";
			
			
		}
		//obj.creator_char_gender = msg[nIndex++];
		//obj.creator_char_name = msg[nIndex++];
		//obj.creator_lover_gender = msg[nIndex++];
		//obj.creator_lover_name = msg[nIndex++];
		text += "\n";
		if(item.creator_char_name.length != 0)
		{
			text += "原始所有者:   ";
			if(item.creator_char_gender == 0)
				text += '<font color="#51b8e3">'+item.creator_char_name+"</font>";
			else
				text += '<font color="#e81c73">'+item.creator_char_name+"</font>";
			if(item.creator_lover_name.length != 0)
			{
				if(item.creator_char_gender == 0)
					text +='和'
				else
					text +='和'
				if(item.creator_lover_gender == 0)
					text += '<font color="#51b8e3">'+item.creator_lover_name+"</font>";
				else
					text += '<font color="#e81c73">'+item.creator_lover_name+"</font>";
			}
		}
		//'<font color="#FFFF00">物品:</font>' +
		//text += '<font color="#FFFF00">暂用测试地址:</font><a href="http://119.145.144.150"><u><font color="#0000FF">点此处进入</font></u></a>';
		textField.setHtmlText(text);
		textField.pack();
		textField.paintImmediately();
		panelBottom.pack();
		panelBottom.paintImmediately();
		var square:Sprite = new Sprite();
		
		square.graphics.beginFill(0x033332, 0.9);
		square.graphics.drawRoundRectComplex(0,0,width,height,5,5,5,5);
		square.graphics.endFill();
		setBackgroundDecorator(new AssetBackground(square as DisplayObject));
		
		panelIcon.filters = enableUse ? null :filterArrayImage;
		panelIcon.pack();
		panelIcon.paintImmediately();
		this.pack();
		this.paintImmediately();
		
	}
	public function clear():void
	{
		setBackgroundDecorator(null);
		panelIcon.setBackgroundDecorator(null);
	}
		
		
}
}